#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using vll = vector<llt>;

template<typename T>
void input(vector<T> & v, int n){
    v.assign(n, {});
    for(int i=1;i<=n;++i) cin >> v[i];
    return;
}

template<typename T>
istream & operator >> (istream & is, vector<T> & v){
    for(auto & i : v) is >> v;
    return is;
}



void work(){
    string s;
    int r, g, b; cin >> r >> g >> b >> s;
    int ans = 0;
    if('R' == s[0]) ans = min(g, b);
    else if('B' == s[0]) ans = min(r, g);
    else ans = min(r, b);
    cout << ans << endl;
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}